package com.lxu;

/**
 * 多线程场景下，content的值可能会在线程中错乱
 * 出现如下问题：thread-0------>thread-3--data
 */
public class ThreadLocalDemo1 {

    private String content;

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public static void main(String[] args) {

        ThreadLocalDemo1 demo = new ThreadLocalDemo1();

        for (int i = 0; i < 100; i++) {
            new Thread(() -> {
                demo.setContent(Thread.currentThread().getName() + "--data");
                System.out.println(Thread.currentThread().getName() + "------>" + demo.getContent());
            }, "thread-" + i).start();
        }
    }
}
